<!--
 * @Author: raoyonggang 11886335+ryg321@user.noreply.gitee.com
 * @Date: 2024-06-04 16:31:26
 * @LastEditors: raoyonggang 11886335+ryg321@user.noreply.gitee.com
 * @LastEditTime: 2024-06-21 10:19:18
 * @FilePath: \v9\src\views\shop\template.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="maincs">
    <div class="main_spac1" style="padding-bottom: 5px">
      <div
        class="main_white padding10 model"
        element-loading-text="加载中"
        v-loading="listLoading"
        style="min-height: 780px"
      >
        <p class="open-type">开通状态：<span :class="`openStatus${companyInfo.open_theme}`">{{ companyInfo.open_theme == 1 ? "已开通" : "未开通" }}</span></p>
        <p class="text">操作步骤：</p>
        <p class="text">1. 选择心仪的主题-点击 “一键应用“ 跳转至商城公众号和小程序会立即应用该主题。</p>
        <p class="text">2. 以下主题模块需付费开通，开通后即可 “一键应用” ，如需开通请联系所属客服或实施工程师。</p>
        <p class="text">3. 如需替换主题模板，可直接在模板列表选择新的主题模板。</p>
        <p class="text">4. 主题中显示限时抢购活动，需在 「营销-限时抢购」 中 ，新增限时抢购活动后才会在商城页面显示。</p>
        <p class="theme-show">主题展示： </p>
        <div class="template-wrap">
          <div class="template-item" v-for="(item, index) in themeList" :key="item.id" @mouseenter="mouseenter(item, index)">
            <div class="masking" v-if="maskingIndex === index">
              <el-button round @click="apply(item, index)" :disabled="item.id == companyInfo.theme_id">一键应用</el-button>
              <el-button v-if="index" class="mg-t-10" round @click="changeShowViewer">预览</el-button>
              <el-image-viewer v-if="showViewer" :on-close="changeShowViewer" :url-list="imgList(item)"></el-image-viewer>
            </div>
            <img :src="item.pre_home_img" alt="">
            <div class="item-text">
              <span></span>
              <p>{{ item.theme_name }}</p>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {
  getThemeList,
  applyTheme
} from "@/api/shop/shop";
import { packApi } from "@/utils/public";
import { mapGetters } from "vuex";
import ElImageViewer from 'element-ui/packages/image/src/image-viewer.vue';
export default {
  components: { ElImageViewer },
  data() {
    return {
      listLoading: false, // 加载loading
      maskingIndex: 0, // 蒙版索引
      themeList: [
        // { theme: require('@/assets/images/template/moren.png'), text: '默认主题' },
      ],
      showViewer: false,
    };
  },
  computed: {
    ...mapGetters([
      "companyInfo",
    ]),
    imgList() {
      return (item)=> {
        return [item.pre_home_img,item.pre_time_img,item.pre_user_img];
      }
    },
  },
  mounted() {
    this.getData();
  },
  methods: {
    getData() {
      getThemeList(packApi()).then(res => {
        this.themeList = res.data.list
      });
    },
    mouseenter (item,index) {
      this.maskingIndex = index;
    },
    apply (item, index) {
      applyTheme(packApi({ theme_id: item.id })).then(res => {
        if(res.errcode == 0) {
          this.$message.success('应用成功');
          this.$store.commit("user/SET_COMINFO",{ ...this.companyInfo, theme_id: item.id});
        }else {
          this.$message.error(res.errmsg);
        }
      })
      // this.$store.dispatch('mallSetting/changeSettingStyle', item.theme)
      // this.$router.push('/shop/index')
    },
    // 预览
    changeShowViewer() {
      this.showViewer = !this.showViewer;
    },
  },
};
</script>
<style lang="scss" scoped>
$text: #333;
.open-type {
  font-size: 14px;
  margin-bottom: 18px;
  color: $text;
  span {
    color: #03A98E;
  }
  .openStatus2 {
    color: #f13130;
  }
}
.text {
  font-size: 14px;
  color: #999999;
  line-height: 24px;
}
.theme-show {
  font-size: 14px;
  color: $text;
  margin-top: 18px;
}
.template-wrap {
  width: 90%;
  display: grid;
  grid-template-columns: repeat(auto-fill, 248px);
  margin-top: 16px;
  grid-gap: 30px;
  .template-item {
    width: 248px;
    height: 540px;
    background: #E8E8E8;
    position: relative;
    border: 1px solid #E8E8E8;
    display: flex;
    flex-direction: column-reverse;
    overflow: hidden;
    .item-text {
      width: 248px;
      height: 40px;
      background: #FFFFFF;
      border: 1px solid #E8E8E8;
      display: flex;
      align-items: center;
      padding: 13px 20px;
      position: relative;
      z-index: 3;
      span {
        display: inline-block;
        width: 2px;
        height: 12px;
        background: #03A98E;
      }
      p {
        font-size: 14px;
        color: #333333;
        font-family: Microsoft YaHei;
        margin-left: 10px;
      }
    }
    .masking {
      width: 100%;
      height: 500px;
      background-color: rgba(175,176,178,.5);
      position: absolute;
      top: 0;
      z-index: 2;
      cursor: pointer;
      display: flex;
      justify-content: center;
      align-items: center;
      flex-direction: column;
      .el-button {
        width: 170px;
        padding: 12px 60px;
        &:hover, &:focus {
          background: #fff;
        }
      }
      .preview {
        color: #03A98E;
      }
    }
    img {
      width: 100%;
      position: absolute;
      top: 0;
      z-index: 1;
    }
  }
}
</style>